<template>
  <div class="table-left-wrapper">
    <div class="header">
      <span class="lb-text">车辆</span>
      <span class="rt-text">日期</span>
      <div class="gap"></div>
    </div>
    <div class="relative">
      <div class="body" :style="{ top: -stockState.scrollTop + 'px' }">
        <template v-for="group in stockState.stockData" :key="group.id">
          <div class="left-td" style="border-right: none">
            <span class="cmodel-name">{{ group.modelName }}</span>
          </div>
          <div class="left-td" v-for="car in group.left_columns" :style="{ height: 40 * car.length + 'px' }" :key="car.carId">
            <!-- 正在使用的车辆 -->
            <div class="using-car" v-if="stockState.selector && stockState.selector.c_id == car.carId">
              <div class="license_No">{{ car.licenseNo }}</div>
              <div class="using-car_tag">当前车辆</div>
              <div class="clash-car" style="margin-left: -15px" v-if="car.length > 1">
                <icon-exclamation-circle-fill class="clash-car_tag" />存在冲突
              </div>
            </div>
            <div class="licenseNo-block" :class="{ pointer: selectable, readonly: !selectable }" @click="onSelect(car)" v-else>
              <div class="flex">
                <a-radio
                  style="flex-shrink: 0; padding: 0 2px 0 3px"
                  :model-value="stockState.selector.id == car.carId"
                  v-if="selectable"
                />
                <div class="licenseNo">{{ car.licenseNo }}</div>
              </div>
              <div class="clash-car" v-if="car.length > 1"> 
                <span v-if="selectable">&nbsp;</span>
                <icon-exclamation-circle-fill class="clash-car_tag" />存在冲突 </div>
            </div>
          </div>
        </template>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
  import { inject } from 'vue'
  export default {
    props: {
      data: Array,
    },
    setup() {
      const stockState = inject('stockState')
      // 是否可选择
      const selectable = stockState.selector != null

      const onSelect = (car: { carId: string }) => {
        if (!selectable) return
        stockState.selector.id = car.carId
        stockState.selector.info = car
      }
      return {
        selectable,
        stockState,
        onSelect,
      }
    },
  }
</script>

<style lang="less" scoped>
  @tdWidth: 120px;
  @tdHeight: 40px;

  .table-left-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: @tdWidth;
    .header {
      position: relative;
      z-index: 20;
      height: @tdHeight;
      background: #f2f3f5;
      overflow: hidden;
      border-right: 1px solid #dedfe0;
      border-bottom: 1px solid #dedfe0;
      // 字
      font-size: 12px;
      color: #1d2129;
      line-height: 20px;

      .gap {
        position: absolute;
        left: -14px;
        top: 21px;
        height: 1px;
        width: 130%;
        background-color: #dde0e6;
        transform: translateY(-50%) rotate(18deg);
      }
      .lb-text {
        position: absolute;
        left: 10px;
        bottom: 4px;
      }
      .rt-text {
        position: absolute;
        top: 4px;
        right: 10px;
      }
    }
    .body {
      position: absolute;
      z-index: 11;

      // 字
      font-size: 14px;
      font-weight: 400;
      color: #1d2129;
      .left-td {
        width: @tdWidth;
        position: relative;
        border-bottom: 1px solid #dedfe0;
        border-right: 1px solid #dedfe0;
        height: @tdHeight;
        line-height: @tdHeight - 2;
        background: #ffffff;
        display: flex;
        .using-car {
          width: 100%;
          background: #f0f4ff;
          cursor: auto;
          padding: 1px 0 0 19px;

          .license_No {
            color: #1890ff;
            line-height: 18px;
            overflow: hidden;
            white-space: nowrap;
          }

          &_tag {
            width: 58px;
            height: 16px;
            line-height: 16px;
            background: #1890ff;
            border-radius: 11px;
            text-align: center;
            font-size: 11px;
            font-weight: 400;
            color: #ffffff;
            margin-bottom: 2px;
          }
        }
        .clash-car {
          font-size: 12px;
          color: #e13f53;
          line-height: 12px;
          &_tag {
            vertical-align: sub;
            font-size: 14px;
            margin-right: 2px;
          }
        }

        .pointer {
          cursor: pointer;
        }

        .licenseNo-block {
          width: 100%;
          // display: flex;
          .licenseNo {
            flex: 1;
            overflow: hidden;
            white-space: nowrap;
            align-items: center;
          }

          &.readonly {
            padding-left: 8px;
          }
        }

        .cmodel-name {
          position: absolute;
          left: 20px;
          white-space: nowrap;
          font-weight: 600;
          font-size: 14px;
          color: #1d2129;
        }
      }
    }
  }
</style>
